home *** CD-ROM | disk | FTP | other *** search
- /***********************************************************************
- * $Id: readstr.c,v 0.80 1994/02/24 09:48:11 zhao Exp $
- *
- *. Copyright(c) 1993,1994 by T.C. Zhao
- * All rights reserved.
- *.
- *
- * Read a token from stream file until EOF or newline or SPACE,
- * but keep at most max characters in buffer s and append '\0'
- * at the end and delete the newline. Returns no. of characters
- * read. Returns EOF only if no characters are read.
- ***********************************************************************/
- #if !defined(lint) && defined(F_ID)
- char *id_getstr = "$Id: readstr.c,v 0.80 1994/02/24 09:48:11 zhao Exp $";
- #endif
-
- #include <stdio.h>
- #include "ulib.h"
-
- #define IS_SEPERATOR(c) ((c) == '\n' || (c) == ' ')
-
- int
- readstring(FILE * file, char s[], register int n)
- {
- register int i, c;
- i = 0;
- n--;
- while ((c = getc(file)) != EOF && !IS_SEPERATOR(c))
- if (i < n)
- s[i++] = c;
- s[i] = '\0';
- return (c == EOF && i == 0 ? EOF : i);
- }
-
- int
- readline(FILE * file, char s[], register int n)
- {
- register int i, c;
- i = 0;
- n--;
- while ((c = getc(file)) != EOF && c != '\n')
- if (i < n)
- s[i++] = c;
- s[i] = '\0';
- return (c == EOF && i == 0 ? EOF : i);
- }
-